package com.edu.state;

/**
 * 线程状态
 * NEW
 * RUNNABLE
 * BLOCKED
 * WAITING
 * TIME_WAITING
 * TERMINATED
 */
public class ThreadState {

    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        System.out.println(t.getName() + " state: " + t.getState());
        t.start();

        while (t.getState() != Thread.State.TERMINATED) {
            System.out.println(t.getName() + " state: " + t.getState());
            Thread.sleep(1000);
            System.out.println(t.getName() + " state: " + t.getState());
        }
        System.out.println(t.getName() + " state: " + t.getState());


    }
}

class T extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                System.out.println(i);
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
